package com.tzjw.marketweixin.pojo.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.tzjw.marketweixin.exception.errorcode.CommonErrorCode;
import com.tzjw.marketweixin.exception.errorcode.ErrorCode;
import lombok.Data;

/**
 * E K T V
 * @author stone
 * @date 2022/01/06 16:24
 * 重构
 */
@Data
@JsonInclude(Include.NON_NULL)
public class BaseRespVo<T> {
    T data;
    String errmsg;
    int errno;

    public BaseRespVo() {
    }

    public BaseRespVo(int errno, String errmsg) {
        this.errmsg = errmsg;
        this.errno = errno;
    }

    public BaseRespVo(ErrorCode errorCode){
        this.errno = errorCode.getCode();
        this.errmsg = errorCode.getDesc();
    }

    public static <T> BaseRespVo ok() {
        return new BaseRespVo<>(CommonErrorCode.SUCCESS);
    }

    public static <T> BaseRespVo ok(T data) {
        BaseRespVo<T> baseRespVo = new BaseRespVo<>(CommonErrorCode.SUCCESS);
        baseRespVo.setData(data);
        return baseRespVo;
    }

    public static <T> BaseRespVo fail(ErrorCode errorCode) {
        BaseRespVo<T> baseRespVo = new BaseRespVo<>(errorCode);
        return baseRespVo;
    }

    public static <T> BaseRespVo fail(String errmsg) {
        return new BaseRespVo<>(500,errmsg);
    }

    public static <T> BaseRespVo invalidData(String msg) {
        return new BaseRespVo<>(504,msg);
    }

    public static <T> BaseRespVo invalidParameter(String msg) {
        return new BaseRespVo<>(400,msg);
    }


}
